package com.iwhalecloud.bss.kite.cucc.service.custview.userinfo.supplier;

import com.iwhalecloud.bss.kite.common.util.KiteMapUtils;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.cucc.common.constant.LocalKeyConsts;
import com.iwhalecloud.bss.kite.cucc.service.custview.userinfo.UserAttrSupplier;
import com.iwhalecloud.bss.kite.cucc.service.custview.userinfo.UserInfoHelper;
import org.springframework.stereotype.Service;

/**
 * 商机名称
 */
@UserAttrSupplier(attrField = LocalKeyConsts.BUSINESS_NAME)
@Service
public class BusinessNameSupplier extends AbstractUserAttrSupplier {

    @Override
    public String getValue() {
        String businessName = UserInfoHelper
            .getValueFromUserItemInfoMap(userInfoContext.getUserItemInfoMap(), LocalKeyConsts.BUSINESS_NAME);
        if (KiteStringUtils.isEmpty(businessName)) {
            businessName = UserInfoHelper
                .getValueFromUserItemInfoMap(userInfoContext.getUserItemInfoMap(), LocalKeyConsts.BUSINESS_NAME_NEW);
        }
        return businessName;
    }

    @Override
    public String getValueDesc() {
        String businessName = getValue();
        if (KiteStringUtils.isEmpty(businessName)) {
            String nicheVal = UserInfoHelper
                .getValueFromUserItemInfoMap(userInfoContext.getUserItemInfoMap(), LocalKeyConsts.BUSINESS);
            if (KiteStringUtils.isEmpty(nicheVal)) {
                nicheVal = UserInfoHelper
                    .getValueFromUserItemInfoMap(userInfoContext.getUserItemInfoMap(), LocalKeyConsts.BUSINESS_NEW);
            }

            String custId = KiteMapUtils.getString(userInfoContext.getUserInfo(), "CUST_ID");
            businessName = UserInfoHelper.getNicheName(nicheVal, custId);
        }

        return businessName;
    }
}
